//
//  YTTDataTool.m
//  跑圈儿
//
//  Created by dllo on 16/4/28.
//  Copyright © 2016年 唐康. All rights reserved.
//

#import "YTTDataTool.h"
#import "YTTCityGroup.h"
#import "YTTDetail.h"
#import "YTTHourly.h"
@implementation YTTDataTool


//单例: 一个类只有一个对象(NSArray)
static YTTDataTool *dataToll = nil;
+ (YTTDataTool *)shareDataManager
{
    if (!dataToll) {
        dataToll = [YTTDataTool new];
    }
    return  dataToll;
}



static NSArray *cityGroupArray = nil;
+ (NSArray *)getAllCityGroups
{
    if (!cityGroupArray) {
        cityGroupArray = [[self alloc] getCityGroups];
    }
    return cityGroupArray;
}

- (NSArray *)getCityGroups
{
    //读取plist文件
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"cityGroups.plist" ofType:nil];
    NSArray *cityGroupArray = [NSArray arrayWithContentsOfFile:plistPath];
    //所有字典对象转成模型对象
    NSMutableArray *mutableArray = [NSMutableArray array];
    for (NSDictionary *dic in cityGroupArray) {
        //声明一个空的TRCityGroup对象
        YTTCityGroup *cityGroup = [YTTCityGroup new];
        //KVC绑定模型对象属性和字典key的关系
        [cityGroup setValuesForKeysWithDictionary:dic];
        [mutableArray addObject:cityGroup];
    }
    
    return [mutableArray copy];

    
}

+ (NSArray *)getAllDailData:(id)requst{
    NSArray *daily_forecast = requst[@"HeWeather data service 3.0"][0][@"daily_forecast"];
    
    NSMutableArray *mutableArray = [NSMutableArray array];
    for (NSDictionary *dic in daily_forecast) {
        YTTDetail *dail = [YTTDetail pareseDailyJosn:dic];
        [mutableArray addObject:dail];
    }
    
    return [mutableArray copy];
}


+(NSArray *)getAllHourlyData:(id)requst{
    NSArray *hourlyArray = requst[@"HeWeather data service 3.0"][0][@"hourly_forecast"];
    NSMutableArray *mutalbeArray = [NSMutableArray array];
    for (NSDictionary *dic in hourlyArray) {
        YTTHourly *hourly = [YTTHourly pareseHourly:dic];
        [mutalbeArray addObject:hourly];
    }
    return [mutalbeArray copy];
    
}


+ (YTTNow *)getNowData:(id)requst{
    YTTNow *now = [YTTNow pareseNowJosnData:requst];
    return now;
}




@end
